//
// sproxy.exe generated file
// do not modify this file
//
// Created: 04/16/2011@22:45:32
//

#pragma once


#if !defined(_WIN32_WINDOWS) && !defined(_WIN32_WINNT) && !defined(_WIN32_WCE)
#pragma message("warning: defining _WIN32_WINDOWS = 0x0410")
#define _WIN32_WINDOWS 0x0410
#endif

#include <atlsoap.h>

namespace TataServices
{

template <typename TClient = CSoapSocketClientT<> >
class CTataServicesT : 
	public TClient, 
	public CSoapRootHandler
{
protected:

	const _soapmap ** GetFunctionMap();
	const _soapmap ** GetHeaderMap();
	void * GetHeaderValue();
	const wchar_t * GetNamespaceUri();
	const char * GetServiceName();
	const char * GetNamespaceUriA();
	HRESULT CallFunction(
		void *pvParam, 
		const wchar_t *wszLocalName, int cchLocalName,
		size_t nItem);
	HRESULT GetClientReader(ISAXXMLReader **ppReader);

public:

	HRESULT __stdcall QueryInterface(REFIID riid, void **ppv)
	{
		if (ppv == NULL)
		{
			return E_POINTER;
		}

		*ppv = NULL;

		if (InlineIsEqualGUID(riid, IID_IUnknown) ||
			InlineIsEqualGUID(riid, IID_ISAXContentHandler))
		{
			*ppv = static_cast<ISAXContentHandler *>(this);
			return S_OK;
		}

		return E_NOINTERFACE;
	}

	ULONG __stdcall AddRef()
	{
		return 1;
	}

	ULONG __stdcall Release()
	{
		return 1;
	}

	CTataServicesT(ISAXXMLReader *pReader = NULL)
		:TClient(_T("http://192.168.8.60:808/tataws/services/TataServices.TataServicesHttpSoap11Endpoint/"))
	{
		SetClient(true);
		SetReader(pReader);
	}
	
	~CTataServicesT()
	{
		Uninitialize();
	}
	
	void Uninitialize()
	{
		UninitializeSOAP();
	}	

	HRESULT request(
		BSTR xml, 
		ATLSOAP_BLOB* __retval
	);

	HRESULT main(
		BSTR args
	);
};

typedef CTataServicesT<> CTataServices;

struct __CTataServices_request_struct
{
	BSTR xml;
	ATLSOAP_BLOB __retval;
};

extern __declspec(selectany) const _soapmapentry __CTataServices_request_entries[] =
{

	{
		0x00020CF1, 
		"xml", 
		L"xml", 
		sizeof("xml")-1, 
		SOAPTYPE_STRING, 
		SOAPFLAG_NONE | SOAPFLAG_IN | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL | SOAPFLAG_NULLABLE,
		offsetof(__CTataServices_request_struct, xml),
		NULL,
		NULL,
		-1,
	},
	{
		0x11515F60, 
		"return", 
		L"return", 
		sizeof("return")-1, 
		SOAPTYPE_BASE64BINARY, 
		SOAPFLAG_NONE | SOAPFLAG_OUT | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL | SOAPFLAG_NULLABLE,
		offsetof(__CTataServices_request_struct, __retval),
		NULL,
		NULL,
		-1,
	},
	{ 0x00000000 }
};

extern __declspec(selectany) const _soapmap __CTataServices_request_map =
{
	0xD54346D8,
	"request",
	L"requestResponse",
	sizeof("request")-1,
	sizeof("requestResponse")-1,
	SOAPMAP_FUNC,
	__CTataServices_request_entries,
	sizeof(__CTataServices_request_struct),
	1,
	-1,
	SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
	0x67E935B8,
	"http://tata.service.tata.cn",
	L"http://tata.service.tata.cn",
	sizeof("http://tata.service.tata.cn")-1
};


struct __CTataServices_main_struct
{
	BSTR args;
};

extern __declspec(selectany) const _soapmapentry __CTataServices_main_entries[] =
{

	{
		0x0037236D, 
		"args", 
		L"args", 
		sizeof("args")-1, 
		SOAPTYPE_STRING, 
		SOAPFLAG_NONE | SOAPFLAG_IN | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL | SOAPFLAG_NULLABLE,
		offsetof(__CTataServices_main_struct, args),
		NULL,
		NULL,
		-1,
	},
	{ 0x00000000 }
};

extern __declspec(selectany) const _soapmap __CTataServices_main_map =
{
	0x00000000,
	"main",
	L"",
	sizeof("main")-1,
	sizeof("")-1,
	SOAPMAP_FUNC,
	__CTataServices_main_entries,
	sizeof(__CTataServices_main_struct),
	0,
	-1,
	SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
	0x67E935B8,
	"http://tata.service.tata.cn",
	L"http://tata.service.tata.cn",
	sizeof("http://tata.service.tata.cn")-1
};

extern __declspec(selectany) const _soapmap * __CTataServices_funcs[] =
{
	&__CTataServices_request_map,
	&__CTataServices_main_map,
	NULL
};

template <typename TClient>
inline HRESULT CTataServicesT<TClient>::request(
		BSTR xml, 
		ATLSOAP_BLOB* __retval
	)
{
    if ( __retval == NULL )
		return E_POINTER;

	HRESULT __atlsoap_hr = InitializeSOAP(NULL);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_INITIALIZE_ERROR);
		return __atlsoap_hr;
	}
	
	CleanupClient();

	CComPtr<IStream> __atlsoap_spReadStream;
	__CTataServices_request_struct __params;
	memset(&__params, 0x00, sizeof(__params));
	__params.xml = xml;

	__atlsoap_hr = SetClientStruct(&__params, 0);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_OUTOFMEMORY);
		goto __skip_cleanup;
	}
	
	__atlsoap_hr = GenerateResponse(GetWriteStream());
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_GENERATE_ERROR);
		goto __skip_cleanup;
	}
	
	__atlsoap_hr = SendRequest(_T("SOAPAction: \"urn:request\"\r\n"));
	if (FAILED(__atlsoap_hr))
	{
		goto __skip_cleanup;
	}
	__atlsoap_hr = GetReadStream(&__atlsoap_spReadStream);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_READ_ERROR);
		goto __skip_cleanup;
	}
	
	// cleanup any in/out-params and out-headers from previous calls
	Cleanup();
	__atlsoap_hr = BeginParse(__atlsoap_spReadStream);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_PARSE_ERROR);
		goto __cleanup;
	}

	*__retval = __params.__retval;
	goto __skip_cleanup;
	
__cleanup:
	Cleanup();
__skip_cleanup:
	ResetClientState(true);
	memset(&__params, 0x00, sizeof(__params));
	return __atlsoap_hr;
}

template <typename TClient>
inline HRESULT CTataServicesT<TClient>::main(
		BSTR args
	)
{

	HRESULT __atlsoap_hr = InitializeSOAP(NULL);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_INITIALIZE_ERROR);
		return __atlsoap_hr;
	}
	
	CleanupClient();

	CComPtr<IStream> __atlsoap_spReadStream;
	__CTataServices_main_struct __params;
	memset(&__params, 0x00, sizeof(__params));
	__params.args = args;

	__atlsoap_hr = SetClientStruct(&__params, 1);
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_OUTOFMEMORY);
		goto __skip_cleanup;
	}
	
	__atlsoap_hr = GenerateResponse(GetWriteStream());
	if (FAILED(__atlsoap_hr))
	{
		SetClientError(SOAPCLIENT_GENERATE_ERROR);
		goto __skip_cleanup;
	}
	
	__atlsoap_hr = SendRequest(_T("SOAPAction: \"urn:main\"\r\n"));
	if (FAILED(__atlsoap_hr))
	{
		goto __skip_cleanup;
	}
	if (GetStatusCode() != 202)
	{
		SetClientError(SOAPCLIENT_SERVER_ERROR);
		__atlsoap_hr = E_FAIL;
	}
	goto __skip_cleanup;
	
__cleanup:
	Cleanup();
__skip_cleanup:
	ResetClientState(true);
	memset(&__params, 0x00, sizeof(__params));
	return __atlsoap_hr;
}

template <typename TClient>
ATL_NOINLINE inline const _soapmap ** CTataServicesT<TClient>::GetFunctionMap()
{
	return __CTataServices_funcs;
}

template <typename TClient>
ATL_NOINLINE inline const _soapmap ** CTataServicesT<TClient>::GetHeaderMap()
{
	static const _soapmapentry __CTataServices_request_atlsoapheader_entries[] =
	{
		{ 0x00000000 }
	};

	static const _soapmap __CTataServices_request_atlsoapheader_map = 
	{
		0xD54346D8,
		"request",
		L"requestResponse",
		sizeof("request")-1,
		sizeof("requestResponse")-1,
		SOAPMAP_HEADER,
		__CTataServices_request_atlsoapheader_entries,
		0,
		0,
		-1,
		SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
		0x67E935B8,
		"http://tata.service.tata.cn",
		L"http://tata.service.tata.cn",
		sizeof("http://tata.service.tata.cn")-1
	};

	static const _soapmapentry __CTataServices_main_atlsoapheader_entries[] =
	{
		{ 0x00000000 }
	};

	static const _soapmap __CTataServices_main_atlsoapheader_map = 
	{
		0x00000000,
		"main",
		L"",
		sizeof("main")-1,
		sizeof("")-1,
		SOAPMAP_HEADER,
		__CTataServices_main_atlsoapheader_entries,
		0,
		0,
		-1,
		SOAPFLAG_NONE | SOAPFLAG_PID | SOAPFLAG_DOCUMENT | SOAPFLAG_LITERAL,
		0x67E935B8,
		"http://tata.service.tata.cn",
		L"http://tata.service.tata.cn",
		sizeof("http://tata.service.tata.cn")-1
	};


	static const _soapmap * __CTataServices_headers[] =
	{
		&__CTataServices_request_atlsoapheader_map,
		&__CTataServices_main_atlsoapheader_map,
		NULL
	};
	
	return __CTataServices_headers;
}

template <typename TClient>
ATL_NOINLINE inline void * CTataServicesT<TClient>::GetHeaderValue()
{
	return this;
}

template <typename TClient>
ATL_NOINLINE inline const wchar_t * CTataServicesT<TClient>::GetNamespaceUri()
{
	return L"http://tata.service.tata.cn";
}

template <typename TClient>
ATL_NOINLINE inline const char * CTataServicesT<TClient>::GetServiceName()
{
	return NULL;
}

template <typename TClient>
ATL_NOINLINE inline const char * CTataServicesT<TClient>::GetNamespaceUriA()
{
	return "http://tata.service.tata.cn";
}

template <typename TClient>
ATL_NOINLINE inline HRESULT CTataServicesT<TClient>::CallFunction(
	void *, 
	const wchar_t *, int,
	size_t)
{
	return E_NOTIMPL;
}

template <typename TClient>
ATL_NOINLINE inline HRESULT CTataServicesT<TClient>::GetClientReader(ISAXXMLReader **ppReader)
{
	if (ppReader == NULL)
	{
		return E_INVALIDARG;
	}
	
	CComPtr<ISAXXMLReader> spReader = GetReader();
	if (spReader.p != NULL)
	{
		*ppReader = spReader.Detach();
		return S_OK;
	}
	return TClient::GetClientReader(ppReader);
}

} // namespace TataServices
